import { Cascader, CascaderProps, Form, Input, message, Select } from "antd"
import { Children, useEffect, useState } from "react";
import HomePage_ModalComponent_CancelAndSubmitFooterComponent from "../../../../../../component/modal/component/cancelAndSubmitFooter"
import { ReactComponent as CascaderArrow } from "../../../../../../../../assets/svg/cascaderArrow.svg"
import lessModule from "./index.module.less";
import { $Http } from "../../../../../../../../network";
import { $eventBus, $EventBus_off, $EventBus_on, $FilterOrganizationRank, $selectOptionData } from "../../../../../../../../common/utils";
import HomePage_DataMaintenancePage_SubstationMaintenancePage_SubstationModalComponent from "../../../../../dataMaintenance/page/substationMaintenance/component/substationModal";
import HomePage_ModalComponent_HeaderNormalComponent from "../../../../../../component/modal/component/headerNormal";
import HomePage_ModalComponent_NormalFooterComponent from "../../../../../../component/modal/component/normalFooter";
import HomePage_DataMaintenancePage_UprightMaintenancePage_ModalComponent from "../../../../../dataMaintenance/page/uprightMaintenance/component/modal";
import HomePage_ModalComponent_SeeMainTransformerOrLineModalComponent from "../../../../../../component/modal/component/seeMainTransformerOrLineModalComponent";


// 主页-账号管理页面-操作弹窗组件
interface componnetInterface {
    isReview?: boolean
    sourceData: object
    change_cancel: Function

}
const HomePage_SystemSettingsPage_ReviewWorkOrderPage_ModalComponnet: React.FC<componnetInterface> = (props) => {
    const [switchIdx, setSwitchIdx] = useState<number>(0)
    
    const groupList = [
        {
            label: "提交时间",
            key: "subTime",
        },
        {
            label: "操作类型",
            key: "operation",
        },
        {
            label: "提交账号",
            key: "subName",
        },
    ]

    const click_review = (value: string) => {
        $Http("systemSettingsHandleWorkOrder", { id: props.sourceData["id"], result: value, alterID: sessionStorage.userID }).then((res) => {
            message.success(res["success"])
            props.change_cancel(true)
        })
    }

    // 广播函数数据
    const eventBusFuncData = {
        // 改前/改后
        reviewWorkOrderSwitchIdx: (data: object) => {
            setSwitchIdx(data["data"]["switchIdx"])
        },
        // 提交操作
        submitOperation: (data: object) => {
            click_review("通过")
        },
    }

    useEffect(() => {
        $EventBus_on(eventBusFuncData)
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])

    return (
        <div className={lessModule["homePageSystemSettingsPageReviewWorkOrderPageModalComponnet"]}>
            <HomePage_ModalComponent_HeaderNormalComponent name="工单详情" padding="11px 24px" isLayoutSetting={props.sourceData["opeName"] === "编辑"} change_cancel={props.change_cancel} />
            <div className={lessModule["homePageSystemSettingsPageReviewWorkOrderPageModalComponnet-card"]}>
                {
                    groupList.map((item, idx) => (
                        <div key={`groupItem${idx}`} className={lessModule["homePageSystemSettingsPageReviewWorkOrderPageModalComponnet-card__group"]}>
                            <span>{item["label"]}：</span>
                            <span className={lessModule["card-group__value"]}>{item["key"] === "operation" ? `${props.sourceData["opeName"]}/${props.sourceData["opeType"]}` : props.sourceData[item["key"]]}</span>
                        </div>
                    ))
                }
            </div>
            {
                props.sourceData["newDetail"]["typeName"] === "数据维护/站点维护" && <HomePage_DataMaintenancePage_SubstationMaintenancePage_SubstationModalComponent isReview sourceData={{ type: "see", ...props.sourceData[switchIdx ? "oldDetail" : "newDetail"] }} change_cancel={props.change_cancel} />
            }
            {
                props.sourceData["newDetail"]["typeName"] === "数据维护/隔直维护" && <HomePage_DataMaintenancePage_UprightMaintenancePage_ModalComponent isReview sourceData={{ type: "see", ...props.sourceData[switchIdx ? "oldDetail" : "newDetail"] }} change_cancel={props.change_cancel} />
            }
            {
                props.sourceData["newDetail"]["typeName"] === "数据维护/主变维护" || props.sourceData["newDetail"]["typeName"] === "数据维护/线路维护" && <HomePage_ModalComponent_SeeMainTransformerOrLineModalComponent isReview sourceData={{ type: "see", ...props.sourceData[switchIdx ? "oldDetail" : "newDetail"] }} change_cancel={props.change_cancel} />
            }

            {
                props.isReview ? <HomePage_ModalComponent_NormalFooterComponent cancelName="不通过" submitName="通过" change_cancel={() => click_review("不通过")} />
                    : <HomePage_ModalComponent_NormalFooterComponent isSubmitHide change_cancel={props.change_cancel} />

            }
        </div>
    )
}
export default HomePage_SystemSettingsPage_ReviewWorkOrderPage_ModalComponnet

